package cn.tedu.tmall.passport.controller;
import cn.tedu.tamll.common.web.JsonResult;
import cn.tedu.tmall.passport.pojo.parm.UserLoginParam;
import cn.tedu.tmall.passport.pojo.po.vo.UserLoginVO;
import cn.tedu.tmall.passport.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/passport")
@Slf4j
@Validated
@Api(tags = "1. 单点登录")
public class UserController {
    @Autowired
    private IUserService userService;
    @PostMapping("/reg")
    @ApiOperation( "注册功能")
    public JsonResult reg(@RequestParam String name, @RequestParam String password){
        return JsonResult.ok();
    }

    @PostMapping("login")
    @ApiOperation( "登录功能")
    public JsonResult login(@RequestBody @Validated UserLoginParam userLoginParam, HttpServletRequest httpServletRequest){
        log.debug("userLoginParam:{}",userLoginParam);
        UserLoginVO userLoginVO =userService.login(userLoginParam,httpServletRequest);
        String mgs = "恭喜你登录成功!!";
        return JsonResult.ok(userLoginVO,mgs);
    }
}
